package com.xy.breakfast.mapper;

import com.xy.breakfast.entity.Cart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CartMapper extends BaseMapper<Cart>{

    @Override
    @Select("select id,clients_id,foods_id,num,price,create_time from cart where id=#{id}")
    @Results({
            //java->mysql
            @Result(property = "id", column = "id"),
            @Result(property = "clientsId", column = "clients_id"),
            @Result(property = "foodsId", column = "foods_id"),
            @Result(property = "num", column = "num"),
            @Result(property = "price", column = "price"),
            @Result(property = "createTime", column = "create_time")
    })
    public Cart getById(int id);

    @Override
    @Insert("insert into cart(clients_id,foods_id,num,price,create_time) values (#{clientsId},#{foodsId},#{num},#{price},#{createTime})")
    public void save(Cart t);


    @Override
    @Delete("delete from cart where id=#{id}")
    public void deleteById(int id);


    @Update("UPDATE cart SET num=#{num}, price=#{price} WHERE id=#{id}")
    void update(Cart cart);

    //获取用户的购物车
    @Select("select id,clients_id,foods_id,num,price,create_time from cart where clients_id=#{clients_id}")
    @Results({
            //java->mysql
            @Result(property = "id", column = "id"),
            @Result(property = "clientsId", column = "clients_id"),
            @Result(property = "foodsId", column = "foods_id"),
            @Result(property = "num", column = "num"),
            @Result(property = "price", column = "price"),
            @Result(property = "createTime", column = "create_time")
    })
    public List<Cart> getByClientsId(int clientsId);

    @Override
    public List<Cart> getAll();

    @Override
    public List<Cart> getPage(int start,int end);
}
